package com.lagou.module2homewor;

/**
 * 棋盘类
 */
public class ChessBoard {
    /**
     * 棋盘的大小
     */
    public static final int BOARD_SIZE = 16;

    /**
       初始化棋盘上的点，每个点都为false
     */
    private boolean[][] chessBoradCheck = new boolean[BOARD_SIZE][BOARD_SIZE];
    private String[][] chessBorad = null;

    /**
     * 给棋盘位置赋值
     * @param posX x坐标
     * @param posY y坐标
     * @param chessman 棋子
     */
    public void setChessBorad(int posX,int posY,String chessman) {
        this.chessBorad[posX][posY] = chessman;
    }

    /**
     * 返回棋盘
     * @return
     */
    public String[][] getChessBoard(){
        return this.chessBorad;
    }

    /**
     * 初始化棋盘
     */
    public void initChessBorad(){
        chessBorad = new String[BOARD_SIZE][BOARD_SIZE];
        for(int i = 0; i < chessBorad.length; i++){
            for(int j = 0; j < chessBorad[i].length; j++){
                chessBorad[i][j] = "+";
            }
        }
    }

    /**
     * 输出棋盘
     */
    public void drawChessBorad(){
        for(int i = 0; i < BOARD_SIZE + 1; i++){
            for(int j = 0; j < BOARD_SIZE + 1; j++){
                if( i + j == 0){
                    System.out.print("\t");
                }
                else if(0 == i && j > 0){
                    System.out.printf("\t\033[34;4m%x\033[0m", j-1);
                }
                else if(0 == j && i > 0){
                    System.out.printf("\t\033[34;4m%x\033[0m",i-1) ;
                }
                else if( i >= 1 & j >= 1){
                        if( chessBorad[i-1][j-1].equals(Chessman.BLACK.getChessman())){
                            System.out.print("\t"+"\033[31;4m"+chessBorad[i-1][j-1]+"\033[0m");
                        }else if(chessBorad[i-1][j-1].equals(Chessman.WHITE.getChessman())) {
                            System.out.print("\t"+"\033[33;4m"+chessBorad[i-1][j-1]+"\033[0m");
                        }else{
                            System.out.print("\t"+chessBorad[i-1][j-1]);
                        }
                }

            }
            System.out.println();

        }
    }
}
